package cn.nhic.web.filter;/**
 * Created by duweiping on 2024/9/6 23:15
 */

import cn.nhic.web.constant.Constants;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 编解码filter
 * @author HttpServletRequestWrapper duweiping
 * @date 2024/9/6 23:15
 */
public class CharacterFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)request;
        HttpServletResponse resp = (HttpServletResponse)response;

        req.setCharacterEncoding(Constants.CharSetEnum.UTF_8.getCharSet());
        resp.setContentType(Constants.DOC_FORMAT_TYPE);

        CharacterRequest characterRequest = new CharacterRequest(req);
        chain.doFilter(characterRequest,resp);
    }



    @Override
    public void destroy() {

    }
}
